﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Drawing;
using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using System.Data;

/// <summary>
/// Summary description for FleetPaymentReceiptPDFOutput
/// </summary>
public class FleetPaymentReceiptPDFOutput
{
    private string _carplatenumber;
    public string CarPlate
    {
        get { return _carplatenumber; }
        set { _carplatenumber = value; }
    }

    private string _customername;
    public string CustomerName
    {
        get { return _customername; }
        set { _customername = value; }
    }

    private string _quoterefno;
    public string QuoteRefNo
    {
        get { return _quoterefno; }
        set { _quoterefno = value; }
    }

    private string _address1;
    public string Address1
    {
        get { return _address1; }
        set { _address1 = value; }
    }

    private string _address2;
    public string Address2
    {
        get { return _address2; }
        set { _address2 = value; }
    }

    private string _address3;
    public string Address3
    {
        get { return _address3; }
        set { _address3 = value; }
    }

    private string _typeofpolicy;
    public string TypeOfPolicy
    {
        get { return _typeofpolicy; }
        set { _typeofpolicy = value; }
    }

    private string _makemodel;
    public string MakeModel
    {
        get { return _makemodel; }
        set { _makemodel = value; }
    }

    private string _annualpremium;
    public string AnnualPremium
    {
        get { return _annualpremium; }
        set { _annualpremium = value; }
    }

    private bool _isbanktransfer;
    public bool IsBankTransfer
    {
        get { return _isbanktransfer; }
        set { _isbanktransfer = value; }
    }

    private bool _iscash;
    public bool IsCash
    {
        get { return _iscash; }
        set { _iscash = value; }
    }

    private bool _ischeckno;
    public bool IsCheckNo
    {
        get { return _ischeckno; }
        set { _ischeckno = value; }
    }

    private string _checkno;
    public string CheckNo
    {
        get { return _checkno; }
        set { _checkno = value; }
    }

    private bool _iscreditcard;
    public bool IsCreditCard
    {
        get { return _iscreditcard; }
        set { _iscreditcard = value; }
    }

    private bool _isvisa;
    public bool IsVisa
    {
        get { return _isvisa; }
        set { _isvisa = value; }
    }

    private bool _ismaster;
    public bool IsMaster
    {
        get { return _ismaster; }
        set { _ismaster = value; }
    }

    private bool _issnstallment;
    public bool IsInstallment
    {
        get { return _issnstallment; }
        set { _issnstallment = value; }
    }

    private DateTime dateTimeNow = CE.Global.General.GetUTCDateTime();

    public string GeneratePDF()
    {
        // First of all initialize the global XPrivateFontCollection.
        XPrivateFontCollection privateFontCollection = XPrivateFontCollection.Global;
        Uri fontUri = new Uri(MappedApplicationPath + "fonts\\");
        LoadPrivateFont(privateFontCollection, fontUri, "./#TH Sarabun New"); 

        // Create a new PDF document
        PdfDocument document = new PdfDocument();
        // Set font encoding to unicode

        XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

        document.Info.Title = "Created with PDFsharp";

        // Create an empty page
        PdfPage page = document.AddPage();

        // Get an XGraphics object for drawing
        XGraphics gfx = XGraphics.FromPdfPage(page);

        
        // Create a font
        XFont fontHeader = new XFont("TH Sarabun New", 18, XFontStyle.Bold, options);
        XFont font = new XFont("TH Sarabun New", 14d, XFontStyle.Regular, options);
        XFont fontAddress = new XFont("TH Sarabun New", 16, XFontStyle.Regular, options);
        XColor _xcolor = new XColor();
        _xcolor.R = 0;
        _xcolor.G = 0;
        _xcolor.B = 0;
        
        XPen _pen = new XPen(_xcolor);
        //System.Drawing.Rectangle _rect = new System.Drawing.Rectangle(40, 40, 535, 460);
        XRect _rect = new XRect(40, 40, 535, 460);
        gfx.DrawRectangle(_pen, _rect);

        int curX = 60;
        int curY = 60;

        gfx.DrawImage(XImage.FromFile(AppDomain.CurrentDomain.BaseDirectory + "/images/logos/gg_logo.png"), new XRect(curX, curY, 83, 73));
        
        gfx.DrawString("บริษัท คอมแพร์เอ็กซ์เพรส นายหน้าประกันภัย (ประเทศไทย) จำกัด", fontHeader, XBrushes.Black, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        curY += 15;

        gfx.DrawString("เลขที่นายหน้าประกันวินาศภัยนิตติบุคคลเลขที่: ว00016/2553", fontAddress, XBrushes.Black, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        curY += 15;

        gfx.DrawString("ชั้น 42 อาคารยูไนเต็ด เซ็นเตอร์ เลขที่ 323 ถนนสีลม", fontAddress, XBrushes.Black, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        curY += 15;

        gfx.DrawString("แขวงสีลม เขตบางรัก กรุงเทพฯ 10500", fontAddress, XBrushes.Black, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        curY += 15;

        gfx.DrawString("โทร 02-268-8222  โทรสาร 02-266-6339", fontAddress, XBrushes.Black, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        curY += 15;

        gfx.DrawString("อีเมล์: support@gluaygluay.com", fontAddress, XBrushes.Blue, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        curY += 30;


        gfx.DrawString("เอกสารยืนยันการชำระค่าเบี้ยประกันภัย", fontHeader, XBrushes.Blue, new XRect(curX, curY, 500, 20), XStringFormat.Center);

        curY += 30;
        //ได้รับค่าเบี้ยประกันภัย จาก   //Premium received from

        gfx.DrawString(Resources.CarInsuranceResultPage.DateNew, font, XBrushes.Black, new XRect(curX + 300, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 400, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(dateTimeNow.ToString("dd-MMM-yyyy"), font, XBrushes.Black, new XRect(curX + 405, curY, 50, 15), XStringFormat.TopLeft);
        

        curY += 15;
        gfx.DrawString(Resources.CarInsurance.ReferenceNo, font, XBrushes.Black, new XRect(curX + 300, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 400, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_quoterefno, font, XBrushes.Black, new XRect(curX + 405, curY, 50, 15), XStringFormat.TopLeft);

        curY += 15;

        curX += 50;
        gfx.DrawString("ได้รับค่าเบี้ยประกันภัย จาก", font, XBrushes.Blue, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);

        curY += 15;
        gfx.DrawString(Resources.CarInsuranceResultPage.CustomerName, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_customername, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        curY += 15;
        gfx.DrawString(Resources.General.CustomerAddress, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_address1, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);
        curY += 15;
        gfx.DrawString(_address2, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);
        curY += 15;
        gfx.DrawString(_address3, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        curY += 20;
        gfx.DrawString(Resources.CarInsurance.InsuranceType, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_typeofpolicy, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        curY += 15;
        gfx.DrawString(Resources.CarInsurance.CarMakeModel, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_makemodel, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        curY += 30;
        gfx.DrawString(Resources.General.AnnualPremium, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 120, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_annualpremium, font, XBrushes.Black, new XRect(curX + 125, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString("บาท", font, XBrushes.Black, new XRect(curX + 170, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString("(รวมอากรแสตมป์และภาษีมูลค่าเพิ่ม)", font, XBrushes.Black, new XRect(curX + 195, curY, 50, 15), XStringFormat.TopLeft);

        curY += 30;
        gfx.DrawString("ชำระโดย", font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);

        gfx.DrawString(Resources.General.BankTransfer, font, XBrushes.Black, new XRect(curX + 50, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 120, curY, 50, 15), XStringFormat.TopLeft);
        if (_isbanktransfer)
        {
            gfx.DrawString("√", font, XBrushes.Black, new XRect(curX + 125, curY, 50, 15), XStringFormat.TopLeft);
        }
        else
        {
            gfx.DrawString("X", font, XBrushes.Black, new XRect(curX + 125, curY, 50, 15), XStringFormat.TopLeft);
        }

        gfx.DrawString(Resources.General.Cash, font, XBrushes.Black, new XRect(curX + 150, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 180, curY, 50, 15), XStringFormat.TopLeft);

        if (_iscash)
        {
            gfx.DrawString("√", font, XBrushes.Black, new XRect(curX + 185, curY, 50, 15), XStringFormat.TopLeft);
        }
        else
        {
            gfx.DrawString("X", font, XBrushes.Black, new XRect(curX + 185, curY, 50, 15), XStringFormat.TopLeft);
        }

        gfx.DrawString(Resources.General.CheckNo, font, XBrushes.Black, new XRect(curX + 220, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 260, curY, 50, 15), XStringFormat.TopLeft);

        if (_ischeckno)
        {
            gfx.DrawString("√", font, XBrushes.Black, new XRect(curX + 265, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString(_checkno, font, XBrushes.Black, new XRect(curX + 295, curY, 50, 15), XStringFormat.TopLeft);
        }
        else
        {
            gfx.DrawString("X", font, XBrushes.Black, new XRect(curX + 265, curY, 50, 15), XStringFormat.TopLeft);
        }

        curY += 15;
        gfx.DrawString(Resources.General.CreditCard, font, XBrushes.Black, new XRect(curX + 50, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 120, curY, 50, 15), XStringFormat.TopLeft);
        if (_iscreditcard)
        {
            gfx.DrawString("√", font, XBrushes.Black, new XRect(curX + 125, curY, 50, 15), XStringFormat.TopLeft);
        }
        else
        {
            gfx.DrawString("X", font, XBrushes.Black, new XRect(curX + 125, curY, 50, 15), XStringFormat.TopLeft);
        }

        gfx.DrawString(Resources.General.Visa, font, XBrushes.Black, new XRect(curX + 150, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 180, curY, 50, 15), XStringFormat.TopLeft);

        if (_isvisa)
        {
            gfx.DrawString("√", font, XBrushes.Black, new XRect(curX + 185, curY, 50, 15), XStringFormat.TopLeft);
        }
        else
        {
            gfx.DrawString("X", font, XBrushes.Black, new XRect(curX + 185, curY, 50, 15), XStringFormat.TopLeft);
        }

        gfx.DrawString(Resources.General.Master, font, XBrushes.Black, new XRect(curX + 220, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 260, curY, 50, 15), XStringFormat.TopLeft);

        if (_ismaster)
        {
            gfx.DrawString("√", font, XBrushes.Black, new XRect(curX + 265, curY, 50, 15), XStringFormat.TopLeft);
        }
        else
        {
            gfx.DrawString("X", font, XBrushes.Black, new XRect(curX + 265, curY, 50, 15), XStringFormat.TopLeft);
        }
        if (_iscreditcard)
        {
            if (_issnstallment)
            {
                curY += 15;
                gfx.DrawString("(" + Resources.General.MonthlyInstallments + ")", font, XBrushes.Black, new XRect(curX + 50, curY, 30, 15), XStringFormat.TopLeft);
            }
        }

        curX -= 50;
        curY += 30;
        gfx.DrawString("หมายเหตุ", fontHeader, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);

        curY += 15;
        gfx.DrawString("- เอกสารฉบับนี้จัดทำด้วยระบบคอมพิวเตอร์ ถือว่าสมบูรณ์โดยไม่ต้องมีลายมือชื่อผู้รับมอบอำนาจ", font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);

        curY += 15;
        gfx.DrawString("- ใบเสร็จรับเงินตัวจริงจะทำการออกให้ท่านโดยบริษัทประกันฯ และส่งให้ท่านพร้อมกับกรมธรรม์ต่อไป", font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);

        curY += 15;
        gfx.DrawString("- ไม่สามารถใช้แทนใบกำกับภาษีได้", font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);

        string _filePath = GetFilePath();
        string filename = _filePath + "PaymentReceipt_" + _quoterefno + "_" + dateTimeNow.ToString("_ddMMMyyyy_hhmmss_tt") + ".pdf"; //DateTime.Now.ToString("_ddMMMyyyy_hhmmss_tt")
        //document.Save(filename);
        // ...and start a viewer.
        //Response.Redirect(filename);
        System.IO.MemoryStream stream = new System.IO.MemoryStream();
        document.Save(filename);
        stream.Close();
        document.Close();
        return filename;
    }

    public string GeneratePDF(int Language)
    {
        // First of all initialize the global XPrivateFontCollection.
        XPrivateFontCollection privateFontCollection = XPrivateFontCollection.Global;
        Uri fontUri = new Uri(MappedApplicationPath + "fonts\\");
        LoadPrivateFont(privateFontCollection, fontUri, "./#TH Sarabun New"); 

        // Create a new PDF document
        PdfDocument document = new PdfDocument();
        // Set font encoding to unicode

        XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

        document.Info.Title = "Created with PDFsharp";

        // Create an empty page
        PdfPage page = document.AddPage();

        // Get an XGraphics object for drawing
        XGraphics gfx = XGraphics.FromPdfPage(page);

        // Create a font
        XFont fontHeader = new XFont("TH Sarabun New", 18, XFontStyle.Bold, options);
        XFont font = new XFont("TH Sarabun New", 14d, XFontStyle.Regular, options);
        XFont fontAddress = new XFont("TH Sarabun New", 16, XFontStyle.Regular, options);
        XColor _xcolor = new XColor();
        _xcolor.R = 0;
        _xcolor.G = 0;
        _xcolor.B = 0;
       
        XPen _pen = new XPen(_xcolor);
        //System.Drawing.Rectangle _rect = new System.Drawing.Rectangle(40, 40, 535, 460);
        XRect _rect = new XRect(40, 40, 535, 460);
        gfx.DrawRectangle(_pen, _rect);

        int curX = 60;
        int curY = 60;

        gfx.DrawImage(XImage.FromFile(AppDomain.CurrentDomain.BaseDirectory + "/images/logos/gg_logo.png"), new XRect(curX, curY, 83, 73));

        if (Language == 1)
        {
            gfx.DrawString("บริษัท คอมแพร์เอ็กซ์เพรส นายหน้าประกันภัย (ประเทศไทย) จำกัด", fontHeader, XBrushes.Black, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        }
        else if (Language == 0)
        {
            gfx.DrawString("CompareXpress Insurance Broker (Thailand) Ltd.", fontHeader, XBrushes.Black, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        }
        curY += 15;

        if (Language == 1)
        {
            gfx.DrawString("เลขที่นายหน้าประกันวินาศภัยนิตติบุคคลเลขที่: ว00016/2553", fontAddress, XBrushes.Black, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        }
        else if (Language == 0)
        {
            gfx.DrawString("Non-life Insurance Broker License Number: ว00016/2553", fontAddress, XBrushes.Black, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        }

        curY += 15;
        if (Language == 1)
        {
            gfx.DrawString("ชั้น 42 อาคารยูไนเต็ด เซ็นเตอร์ เลขที่ 323 ถนนสีลม", fontAddress, XBrushes.Black, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        }
        else if (Language == 0)
        {
            gfx.DrawString("42nd Floor, United Center Building,", fontAddress, XBrushes.Black, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        }

        curY += 15;
        if (Language == 1)
        {
            gfx.DrawString("แขวงสีลม เขตบางรัก กรุงเทพฯ 10500", fontAddress, XBrushes.Black, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        }
        else if (Language == 0)
        {
            gfx.DrawString("323 Silom Road, Bangrak, Bangkok 10500", fontAddress, XBrushes.Black, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        }

        curY += 15;
        if (Language == 1)
        {
            gfx.DrawString("โทร 02-268-8222  โทรสาร 02-266-6339", fontAddress, XBrushes.Black, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        }
        else if (Language == 0)
        {
            gfx.DrawString("Tel. 02-268-8222 Fax. 02-266-6339", fontAddress, XBrushes.Black, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        }
        curY += 15;

        if (Language == 1)
        {
            gfx.DrawString("อีเมล์: support@gluaygluay.com", fontAddress, XBrushes.Blue, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        }
        else if (Language == 0)
        {
            gfx.DrawString("email: support@gluaygluay.com", fontAddress, XBrushes.Blue, new XRect(curX + 90, curY, 50, 20), XStringFormat.TopLeft);
        }
        curY += 30;

        if (Language == 1)
        {
            gfx.DrawString("เอกสารยืนยันการชำระค่าเบี้ยประกันภัย", fontHeader, XBrushes.Blue, new XRect(curX, curY, 500, 20), XStringFormat.Center);
        }
        else if (Language == 0)
        {
            gfx.DrawString("Confirmation receipt", fontHeader, XBrushes.Blue, new XRect(curX, curY, 500, 20), XStringFormat.Center);
        }

        curY += 30;

        gfx.DrawString(Resources.CarInsuranceResultPage.DateNew, font, XBrushes.Black, new XRect(curX + 300, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 400, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(dateTimeNow.ToString("dd-MMM-yyyy"), font, XBrushes.Black, new XRect(curX + 405, curY, 50, 15), XStringFormat.TopLeft);
        

        curY += 15;
        gfx.DrawString(Resources.CarInsurance.ReferenceNo, font, XBrushes.Black, new XRect(curX + 300, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 400, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_quoterefno, font, XBrushes.Black, new XRect(curX + 405, curY, 50, 15), XStringFormat.TopLeft);

        curY += 15;

        curX += 50;
        if (Language == 1)
        {
            gfx.DrawString("ได้รับค่าเบี้ยประกันภัย จาก", font, XBrushes.Blue, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
        }
        else if (Language == 0)
        {
            gfx.DrawString("Received the premium from", font, XBrushes.Blue, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
        }

        curY += 15;
        gfx.DrawString(Resources.CarInsuranceResultPage.CustomerName, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_customername, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        curY += 15;
        gfx.DrawString(Resources.General.CustomerAddress, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_address1, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);
        curY += 15;
        gfx.DrawString(_address2, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);
        curY += 15;
        gfx.DrawString(_address3, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        curY += 20;
        gfx.DrawString(Resources.CarInsurance.InsuranceType, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_typeofpolicy, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        curY += 15;
        gfx.DrawString(Resources.CarInsurance.CarMakeModel, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_makemodel, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        curY += 30;
        gfx.DrawString(Resources.General.AnnualPremium, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 120, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_annualpremium, font, XBrushes.Black, new XRect(curX + 125, curY, 50, 15), XStringFormat.TopLeft);
        if (Language == 1)
        {
            gfx.DrawString("บาท", font, XBrushes.Black, new XRect(curX + 170, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString("(รวมอากรแสตมป์และภาษีมูลค่าเพิ่ม)", font, XBrushes.Black, new XRect(curX + 195, curY, 50, 15), XStringFormat.TopLeft);
        }
        else if (Language == 0)
        {
            gfx.DrawString("baht", font, XBrushes.Black, new XRect(curX + 170, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString("(Including stamp duty and VAT)", font, XBrushes.Black, new XRect(curX + 195, curY, 50, 15), XStringFormat.TopLeft);
        }

        curY += 30;
        if (Language == 1)
        {
            gfx.DrawString("ชำระโดย", font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        }
        else if (Language == 0)
        {
            gfx.DrawString("Paid by ", font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        }

        gfx.DrawString(Resources.General.BankTransfer, font, XBrushes.Black, new XRect(curX + 50, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 120, curY, 50, 15), XStringFormat.TopLeft);
        if (_isbanktransfer)
        {
            gfx.DrawString("√", font, XBrushes.Black, new XRect(curX + 125, curY, 50, 15), XStringFormat.TopLeft);
        }
        else
        {
            gfx.DrawString("X", font, XBrushes.Black, new XRect(curX + 125, curY, 50, 15), XStringFormat.TopLeft);
        }

        gfx.DrawString(Resources.General.Cash, font, XBrushes.Black, new XRect(curX + 150, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 180, curY, 50, 15), XStringFormat.TopLeft);

        if (_iscash)
        {
            gfx.DrawString("√", font, XBrushes.Black, new XRect(curX + 185, curY, 50, 15), XStringFormat.TopLeft);
        }
        else
        {
            gfx.DrawString("X", font, XBrushes.Black, new XRect(curX + 185, curY, 50, 15), XStringFormat.TopLeft);
        }

        gfx.DrawString(Resources.General.CheckNo, font, XBrushes.Black, new XRect(curX + 220, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 260, curY, 50, 15), XStringFormat.TopLeft);

        if (_ischeckno)
        {
            gfx.DrawString("√", font, XBrushes.Black, new XRect(curX + 265, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString(_checkno, font, XBrushes.Black, new XRect(curX + 295, curY, 50, 15), XStringFormat.TopLeft);
        }
        else
        {
            gfx.DrawString("X", font, XBrushes.Black, new XRect(curX + 265, curY, 50, 15), XStringFormat.TopLeft);
        }

        curY += 15;
        gfx.DrawString(Resources.General.CreditCard, font, XBrushes.Black, new XRect(curX + 50, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 120, curY, 50, 15), XStringFormat.TopLeft);
        if (_iscreditcard)
        {
            gfx.DrawString("√", font, XBrushes.Black, new XRect(curX + 125, curY, 50, 15), XStringFormat.TopLeft);
        }
        else
        {
            gfx.DrawString("X", font, XBrushes.Black, new XRect(curX + 125, curY, 50, 15), XStringFormat.TopLeft);
        }

        gfx.DrawString(Resources.General.Visa, font, XBrushes.Black, new XRect(curX + 150, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 180, curY, 50, 15), XStringFormat.TopLeft);

        if (_isvisa)
        {
            gfx.DrawString("√", font, XBrushes.Black, new XRect(curX + 185, curY, 50, 15), XStringFormat.TopLeft);
        }
        else
        {
            gfx.DrawString("X", font, XBrushes.Black, new XRect(curX + 185, curY, 50, 15), XStringFormat.TopLeft);
        }

        gfx.DrawString(Resources.General.Master, font, XBrushes.Black, new XRect(curX + 220, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 260, curY, 50, 15), XStringFormat.TopLeft);

        if (_ismaster)
        {
            gfx.DrawString("√", font, XBrushes.Black, new XRect(curX + 265, curY, 50, 15), XStringFormat.TopLeft);
        }
        else
        {
            gfx.DrawString("X", font, XBrushes.Black, new XRect(curX + 265, curY, 50, 15), XStringFormat.TopLeft);
        }
        if (_iscreditcard)
        {
            if (_issnstallment)
            {
                curY += 15;
                gfx.DrawString("(" + Resources.General.MonthlyInstallments + ")", font, XBrushes.Black, new XRect(curX + 50, curY, 30, 15), XStringFormat.TopLeft);
            }
        }

        curX -= 50;
        curY += 30;
        if (Language == 1)
        {
            gfx.DrawString("หมายเหตุ", fontHeader, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        }
        else if (Language == 0)
        {
            gfx.DrawString("Note", fontHeader, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        }

        curY += 15;
        if (Language == 1)
        {
            gfx.DrawString("- เอกสารฉบับนี้จัดทำด้วยระบบคอมพิวเตอร์ ถือว่าสมบูรณ์โดยไม่ต้องมีลายมือชื่อผู้รับมอบอำนาจ", font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        }
        else if (Language == 0)
        {
            gfx.DrawString("- This document is computer generated. It is considered complete without the signature of an authorized person.", font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        }

        curY += 15;
        if (Language == 1)
        {
            gfx.DrawString("- ใบเสร็จรับเงินตัวจริงจะทำการออกให้ท่านโดยบริษัทประกันฯ และส่งให้ท่านพร้อมกับกรมธรรม์ต่อไป", font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        }
        else if (Language == 0)
        {
            gfx.DrawString("- Original receipt will be issued to you by the insurance company.", font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
            curY += 15;
            gfx.DrawString("  And will be sent to you along with the policy document.", font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        }

        curY += 15;
        if (Language == 1)
        {
            gfx.DrawString("- ไม่สามารถใช้แทนใบกำกับภาษีได้", font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        }
        else if (Language == 0)
        {
            gfx.DrawString("- This document cannot be used as tax invoice.", font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        }

        string _filePath = GetFilePath();
        string filename = _filePath + "PaymentReceipt_" + _quoterefno + "_" + dateTimeNow.ToString("_ddMMMyyyy_hhmmss_tt") + ".pdf"; //DateTime.Now.ToString("_ddMMMyyyy_hhmmss_tt")

        System.IO.MemoryStream stream = new System.IO.MemoryStream();
        document.Save(filename);
        stream.Close();
        document.Close();
        return filename;
    }

    protected void LoadPrivateFont(XPrivateFontCollection privateFontCollection, Uri fontUri, string sFontFamilyname)
    {
        //Every font must be added to the global font collection.  There is probably some better way to do this but this was the only method that seemed to work when deploying to any server.
        //If the font has previously been added it will just error out and continue, this does not matter.
        try
        {
            privateFontCollection.Add(fontUri, sFontFamilyname);
        }
        catch
        {
        }
    }

    public static string MappedApplicationPath
    {
        get
        {
            //Returns the absolute path to files from your website - this is needed for font embedding
            string APP_PATH = System.Web.HttpContext.Current.Request.ApplicationPath.ToLower();
            if (APP_PATH == "/")      //a site
                APP_PATH = "/";
            else if (!APP_PATH.EndsWith(@"/")) //a virtual
                APP_PATH += @"/";

            string it = System.Web.HttpContext.Current.Server.MapPath(APP_PATH);
            if (!it.EndsWith(@"\"))
                it += @"\";
            return it;
        }
    } 

    private string GetFilePath()
    {
        string _filePath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NonGGFileOutputPath").ToString();
        _filePath += "pdfoutput\\carinsurance\\fleet\\";
        CE.InputOut.MyIO _myIO = new CE.InputOut.MyIO();

        string _curYear = dateTimeNow.ToString("yyyy"); //DateTime.Now.ToString("yyyy");
        if (!_myIO.CheckDirectory(_filePath + _curYear))
        {
            if (_myIO.CreateDirectory(_filePath, _curYear))
            {
                _filePath += _curYear + "\\";
            }
        }
        else
        {
            _filePath += _curYear + "\\";
        }

        string _curMonth = dateTimeNow.ToString("MMMM"); //DateTime.Now.ToString("MMMM");
        if (!_myIO.CheckDirectory(_filePath + _curMonth))
        {
            if (_myIO.CreateDirectory(_filePath, _curMonth))
            {
                _filePath += _curMonth + "\\";
            }
        }
        else
        {
            _filePath += _curMonth + "\\";
        }

        string _todaydate = dateTimeNow.ToString("ddMMMMyyyy"); //DateTime.Now.ToString("ddMMMMyyyy");
        if (!_myIO.CheckDirectory(_filePath + _todaydate))
        {
            if (_myIO.CreateDirectory(_filePath, _todaydate))
            {
                _filePath += _todaydate + "\\";
            }
        }
        else
        {
            _filePath += _todaydate + "\\";
        }

        string _payments = "Payments_" + _todaydate;
        if (!_myIO.CheckDirectory(_filePath + _payments))
        {
            if (_myIO.CreateDirectory(_filePath, _payments))
            {
                _filePath += _payments + "\\";
            }
        }
        else
        {
            _filePath += _payments + "\\";
        }

        return _filePath;
    }

}
